<?php 
    session_start();
    require_once '../../DAO/DaoCadastrarUsuario.php';
    $validaAcesso = new DaoCadastrarUsuario();
    $validaAcesso->validaAcesso();
?>    
   <?php require 'cabecalho.php'; ?>
<div id="miolo">
    <div id="categorias">
        <?php require_once 'menu_categorias.php'; ?>
    </div>	
    <div id="conteudo">
        <div class="containers">
            <p class="titulo-cadastro" align="center">Finalizando compras</p>                   
            <table width="100%">
                <thead>
                    <tr>
                        <th align="left">Produto</th>
                        <th >Quantidade</th>
                        <th align="center">Pre&ccedil;o</th>
                        <th >SubTotal</th>   
                        <th >Total</th>
                    </tr>
                    <tr><td colspan="5"><hr/></td></tr>
                </thead>
                 <form method="POST" action="?acao=up">
                    <tfoot>
                        <tr><td align="left"> <a href="index.php"><input type="button" value="Continuar Compra" class="bt_fanalizar"/></a></td>
                            <td colspan="5"><a href="boleto.php" onclick="window.open(this.href,'boleto','width=800, height=820'); return false;">
                                    <input type="submit" class="bt_buscar" value="Gerar Boleto"/></a>
                        </td></tr>                                                                                                                    
                    </tfoot>                        
                    <tbody>                        
                      <?php
                        $total = 0.0;
                        if (count($_SESSION['carrinho']) == 0) {
                            echo '<tr><td colspan="5" align="center"><strong>N&atilde;o h&aacute; produtos no carrinho.</strong></td></tr>';
                        } else {
                            $con = new Conexao();
                            $con->conecta();
                            foreach ($_SESSION['carrinho'] as $id => $qtd) {
                                $sql = "select * from produto where prod_id = '$id'";
                                $result = mysql_query($sql) or die("Erro de consulta");
                                $linha = mysql_fetch_assoc($result);
                                $nome = $linha['prod_nome'];
                                $preco = number_format($linha['prod_valor'], 2, ',', '.');
                                $subtotal = number_format($linha['prod_valor'] * $qtd, 2, ',', '.');
                                $total += number_format($linha['prod_valor'] * $qtd, 2, ',', '.');
                                echo '<tr>
                                        <td align="left">' . $nome . '</td>
                                        <td><input class="textquantidade" name="produto[' . $id . ']" type="text" value="' . $qtd . '" size="2" disabled="disabled"/></td>
                                        <td>R$ ' . $preco . '</td>
                                        <td>R$ ' . $subtotal . '</td>
                                        <td align="center"><a href="?acao=del&id=' . $id . '"><div class="bt-comprar">Remover</div></a></td>
                                    </tr>';
                            }
                            $con->desconnecta();
                            echo '<td colspan="4" align="left"><hr>
                                              </td><td align="right"><strong>R$ ' . $total . '</strong></td>';                            
                        }
                        ?>                             
                    </tbody>
                 </form>    
            </table>                                      
        </div>
        
</div>
<?php include 'rodape.php'; ?>